package com.cloud.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Socket;

public class OldIoClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("192.168.1.201", 2404);
        String fileName = "U:\\messes\\SpringbootProject\\netty\\netty学习.docx";
        FileInputStream fileInputStream = new FileInputStream(fileName);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] buffer = new byte[4096];
        long readCount;
        long total = 0;

        long startTime = System.currentTimeMillis();

        while ((readCount = fileInputStream.read(buffer)) >= 0) {
            total+=readCount;
            dataOutputStream.write(buffer);
        }

        System.out.println("发送总字节数："+total+",耗时："+(System.currentTimeMillis()-startTime));
        dataOutputStream.close();
        socket.close();
        fileInputStream.close();
    }
}
